﻿using Unity.Entities;
using UnityEngine;

public class EntitiesReferencesAuthoring : MonoBehaviour
{
    public GameObject bulletPrefabGameObject;
    public GameObject zombieGameobject;
    public GameObject shootlightPrefaGameobject;
    public GameObject scoutPrefabGameobject;
    public GameObject soldierPrefabGameobject;

    /// <summary>
    /// 建筑塔实体
    /// </summary>
    public GameObject buildingTowePrefabGameobject;
    /// <summary>
    /// 建筑兵营预制件
    /// </summary>
    public GameObject buildingBarracksPrefabGameobject;
    public class Baker : Baker<EntitiesReferencesAuthoring>
    {
        public override void Bake(EntitiesReferencesAuthoring authoring)
        {
            Entity entity = GetEntity(TransformUsageFlags.Dynamic);
            AddComponent(entity, new EntitiesReferences
            {
                bulletPrefabEntity = GetEntity(authoring.bulletPrefabGameObject, TransformUsageFlags.Dynamic),
                zombiePrefabEntity = GetEntity(authoring.zombieGameobject, TransformUsageFlags.Dynamic),
                shootlightPrefabEntity = GetEntity(authoring.shootlightPrefaGameobject, TransformUsageFlags.Dynamic),
                scoutPrefabEntity = GetEntity(authoring.scoutPrefabGameobject, TransformUsageFlags.Dynamic),
                soldierPrefabEntity = GetEntity(authoring.soldierPrefabGameobject, TransformUsageFlags.Dynamic),
                buildingTowePrefabEntity = GetEntity(authoring.buildingTowePrefabGameobject, TransformUsageFlags.Dynamic),
                buildingBarracksPrefabEntity = GetEntity(authoring.buildingBarracksPrefabGameobject, TransformUsageFlags.Dynamic),
            });
        }
    }
}


public struct EntitiesReferences : IComponentData
{
    public Entity bulletPrefabEntity;
    public Entity zombiePrefabEntity;
    public Entity shootlightPrefabEntity;
    public Entity scoutPrefabEntity;
    public Entity soldierPrefabEntity;

    /// <summary>
    /// 建筑塔实体
    /// </summary>
    public Entity buildingTowePrefabEntity;
    /// <summary>
    /// 建筑兵营预制件
    /// </summary>
    public Entity buildingBarracksPrefabEntity;
}
